package util;


import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;


	@SuppressWarnings("serial")
	public class DataUtil implements Serializable {

		public static final String DD_MM_YYYY = "dd/MM/yyyy";
		public static final String DAY = "d";
		public static final String MONTH = "MM";
		public static final String YEAR = "yyyy";
		public static final String HH_MM = "HH:mm";
		public static final String DD_MM_YYYY_HH_MM = "dd/MM/yyyy HH:mm";
		public static final String DD_MM_YYYY_HH_MM_SS = "dd/MM/yyyy HH:mm:ss";
		public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

		public static int getAno() {
			return getAno(new Date());
		}

		public static int getAno(Date data) {
			return Integer.valueOf(formt(data, DataUtil.YEAR));
		}

		public static int getMes() {
			return getMes(new Date());
		}

		public static int getMes(Date data) {
			return Integer.valueOf(formt(data, DataUtil.MONTH));
		}

		public static int getDiaMesAtual() {
			return Integer.valueOf(formt(new Date(), DataUtil.DAY));
		}

		public static String getData(Date data) {
			return formt(data, DataUtil.DD_MM_YYYY);
		}

		public static String getData() {
			return formt(new Date(), DataUtil.DD_MM_YYYY);
		}

		public static String getDataHoras() {
			return formt(new Date(), DataUtil.DD_MM_YYYY_HH_MM_SS);
		}

		public static String getDataHoras(Date data) {
			return formt(data, DataUtil.DD_MM_YYYY_HH_MM_SS);
		}

		public static String getDataHorasBanco(Date data) {
			return formt(data, DataUtil.YYYY_MM_DD_HH_MM_SS);
		}

		public static String getHoras() {
			return formt(new Date(), "HH_MM");
		}

		private static Date addData(Date data, Integer periodo, int field) {
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(data);
			calendar.add(field, periodo);
			return calendar.getTime();
		}

		public static Date addMes(Date data, Integer periodo) {
			return addData(data, periodo, Calendar.MONTH);
		}

		public static Date addAno(Date data, Integer periodo) {
			return addData(data, periodo, Calendar.YEAR);
		}

		public static Date subtrairAno(Date data, Integer periodo) {
			return addData(data, periodo * (-1), Calendar.YEAR);
		}

		public static Date subtrairMes(Date data, Integer periodo) {
			return addData(data, periodo * (-1), Calendar.MONTH);
		}

		public static String formt(Date data, String pattern) {
			SimpleDateFormat formatData = new SimpleDateFormat(pattern);
			return formatData.format(data);
		}

		public static String dataTime(Date data, boolean isZeroTime) {
			GregorianCalendar gc = new GregorianCalendar();
			gc.setTime(data);
			if (isZeroTime) {
				gc.set(Calendar.HOUR_OF_DAY, 0);
				gc.set(Calendar.MINUTE, 0);
				gc.set(Calendar.SECOND, 0);
				gc.set(Calendar.MILLISECOND, 0);

			}
			return getDataHorasBanco(gc.getTime());
		}

		public static Date getDataTimeComTime0(Date data) {
			GregorianCalendar gc = new GregorianCalendar();
			gc.setTime(data);
			gc.set(Calendar.HOUR_OF_DAY, 0);
			gc.set(Calendar.MINUTE, 0);
			gc.set(Calendar.SECOND, 0);
			gc.set(Calendar.MILLISECOND, 0);

			return gc.getTime();
		}

		/*public static String calcularIntervalo(List<DataTO> lista, Date dataIncio,
				Date dataFim) {
			Duration dur = null;
			DateTime dt = null;
			DateTime start = new DateTime(dataIncio);
			DateTime end = new DateTime(dataFim);
			for (DataTO td : lista) {
				dur = new Duration(new DateTime(td.getDataInicial()), new DateTime(
						td.getDataFinal()));
				if (dt == null) {
					dt = start.plus(dur);
				} else {
					dt = dt.plus(dur);
				}
			}
			if (dt == null) {
				dur = new Duration(start, end);
			} else {
				dur = new Duration(dt, end);
			}

			return gerarRetorno(dur);
		}*/

		/**
		 * TODO: Insira comentario explicativo AQUI.
		 */
		/*private static String gerarRetorno(Duration dur) {
			long dias = dur.getStandardDays();
			long horas = dur.getStandardHours();
			long minutos = dur.getStandardMinutes();
			long segundos = dur.getStandardSeconds();

			StringBuilder sb = new StringBuilder();
			sb.append(dias).append("d ");
			sb.append(horas % 24).append("h ");
			sb.append(minutos % 60).append("m ");
			sb.append(segundos % 60 % 60).append("s ");

			return sb.toString();
		}*/

		public static void main(String[] args) {
			System.out.println(dataTime(new Date(), true));
		}

	}
